import { defineStore } from "pinia";
import { computed, ref } from "vue";

export const useTokenStore = defineStore("token" ,()=>{
    //定义state
    const token = ref(null);
    //获取state
    const tokenStr = computed(()=>{
        return token.value;
    })
    //修改state
    function update(tk){
        token.value=tk;
    }
    //重置state
    function $reset() {
        token.value=null;
    }
    return {token,tokenStr,update,$reset};
},{
    persist:{
        key: 'token',
        storage: sessionStorage,
        paths: ['token']
    }
});